import React, { useState } from 'react';
import { Button, Modal,Form  } from 'antd';
import CformItem from '@/components/formItem';
type CFormProps = {
    form:any;
    options:any[];
    onChange:(info:any)=>void;

}
const CForm:React.FC<CFormProps> = (props) => {
    props.options.map((item)=>{
        props.form.setFieldsValue({[item.name]:""});
    })
    return (
        <>
            <Form
                labelCol={{ span: 4 }}
                wrapperCol={{ span: 14 }}
                layout="horizontal"
                form={props.form}
                style={{ maxWidth: 600 }}
                >
                    {
                        props.options.map((item) => {
                            return <Form.Item label={item.label} name={item.name} key={item.name}>
                                        <CformItem
                                            type={item.type}
                                            name={item.name}
                                            rules={item.rules}
                                            options={item.options}
                                            value={item.value}
                                            onChange={props.onChange}
                                            form={props.form}
                                            fieldNames={item.fieldNames}
                                            searchable={item.searchable}
                                        />
                                    </Form.Item>
                        })

                    }

                
            </Form>
        </>
    )
}

export default CForm;
